package org.example.maven.controller;

import org.example.maven.annotation.ReadOnlyMode;
import org.example.maven.annotation.logAnnotation;
import org.example.maven.pojo.ProvenanceSource;
import org.example.maven.pojo.Result;
import org.example.maven.service.ProvenanceSourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/provenanceSource")
public class ProvenanceSourceController {
    @Autowired
    private ProvenanceSourceService provenanceSourceService;
    @PostMapping
    @ReadOnlyMode
    @PreAuthorize("hasAnyAuthority('collection:all')")
    @logAnnotation(
            type = "新增",
            detail = "新增来源信息的id为{#provenanceSource.id}"
    )
    //添加来源分类信息
    //@PreAuthorize("hasAnyAuthority('collection:add')")
    public Result addProvenanceSource(@RequestBody ProvenanceSource provenanceSource){
        provenanceSourceService.addProvenanceSource(provenanceSource);
        return Result.success();
    }

    @GetMapping
    @PreAuthorize("hasAnyAuthority('collection:all')")
    //获取藏品来源信息
    //@PreAuthorize("permitAll()")
    public Result getProvenanceSourceById(@RequestParam("collectionId") Integer collectionId){
        return Result.success(provenanceSourceService.getProvenanceSourceById(collectionId));
    }
}
